package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"oss-api/app/service"
	"oss-api/library/request"
	"oss-api/library/response"
)

var Category = new(CategoryApi)

type CategoryApi struct{}

// CreateCategory 创建分类
func (c *CategoryApi) CreateCategory(ctx *gin.Context) {
	var params request.CreateCategoryVo
	if err := ctx.ShouldBind(&params); err != nil {
		ctx.JSON(http.StatusBadRequest, response.Fail(err.Error()))
		return
	}
	category, err := service.Category.AddCategory(params)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, response.Fail(err.Error()))
		return
	}
	ctx.JSON(http.StatusOK, response.Success(category))
}

// CustomCategory 自定义分类
func (c *CategoryApi) CustomCategory(ctx *gin.Context) {
	data, err := service.Category.GetCustomCategory()
	if err != nil {
		ctx.JSON(http.StatusBadRequest, response.Fail(err.Error()))
		return
	}
	ctx.JSON(http.StatusOK, response.Success(data))
}
